# -*- coding: utf-8 -*-
from django.utils.deprecation import MiddlewareMixin
from django.shortcuts import redirect


class Login_required(MiddlewareMixin):
	'''判断用户是否已登录'''
	white_list = ['/login/', ]

	def process_request(self, request):
		now_url = request.path_info
		if now_url in self.white_list:
			return
		else:
			usr = request.session.get('usr')  # 获取session中的user
			if usr:
				return
		if now_url == 'logout':
			return redirect('/login/')
		return redirect('/login?return_url={}'.format(now_url))
